/* Exercise 5.48
   ejer5_48.c */
#include <stdio.h>

/* function prototypes */
long fibonacci(int number);
long fibonacciAux(int number, long fibo0, long fibo1);

/* function main begins program execution */
int main( void )
{
    int number;

    printf("Enter a number: ");
    scanf("%d", &number);

    printf("The fibonnaci number is: %ld\n", fibonacci(number));
	return 0; /* indicate that program ended successfully */
} /* end function main */

long fibonacci(int number)
{
    return fibonacciAux(number, 0, 1);
}

long fibonacciAux(int number, long fibo0, long fibo1)
{
    if (number == 1)
        return fibo1;
    else
        return fibonacciAux(number - 1, fibo1, fibo0 + fibo1);
}
